package com.verbetia.mbrainz.search;

import java.io.IOException;
import java.util.ArrayList;
import org.apache.lucene.queryParser.ParseException;

public class TrackSearchController {
	
	private ArrayList<ResultItem> results;
	public String query;
	
	
	public void setQuery(String query)
	{	
		
		this.query = query;
		
		long start = System.currentTimeMillis();
		
		try {
			results = TrackSearch.getInstance().searchTrack(query);
		} catch (IOException e)
		{
			System.out.println("Unable to search " + e);
		}
		catch  (ParseException pe)
		{
			System.out.println("Unable to search " + pe);
		}
		
		long elapsedTime = System.currentTimeMillis() - start;
		
		System.out.println("Search elapsed: " + elapsedTime + " milliseconds ");
		

				
	}
	
	
	public ArrayList<ResultItem> getQuery()
	{   
		if (results==null)
			results = new ArrayList<ResultItem>();
		return results;
	}
	
	public void searchTrack(String q)
	{
		try {
			results = TrackSearch.getInstance().searchTrack(q);
		} catch (IOException e)
		{
			System.out.println("Unable to search " + e);
		}
		catch  (ParseException pe)
		{}
		
	}
	
	
	public ArrayList<ResultItem> getResults()
	{		
		return this.results;		
	}
	
	
	

}
